//＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊
//管理员权限：1、查看、添加、修改下级帐户信息（密码、个人资料）
//            2、创建、删除下级帐户
//            
//＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊

#include"my.h"

void read_teacher_info(T_LINK **head)//读取教师文件内容至链表
{
    T_INFO tmp_info;
    int flag_read;
    int flag_scan_update_user=0;

    FILE *read;

    T_LINK*p;
    T_LINK*new_point;

    *head=malloc(sizeof(T_LINK));
    memset(*head,0,sizeof(T_LINK));
    p=*head;

    read=fopen(TPATH,"rb");//读取已有帐号和密码保存的文件

    if(read==NULL)//文件打开失败，帐号和密码保存的那个文件不存在时触发
    {
	read=fopen(TPATH,"w");
	fclose(read);
	return;
    }
    else//文件打开成功，进入帐号和密码匹配
    {
	while(1)//循环读取结构体的帐号和密码，读完整个文件退出循环
	{
	    fseek(read,flag_scan_update_user*sizeof(T_INFO),SEEK_SET);
	    flag_read=fread(&tmp_info,sizeof(T_INFO),1,read);

	    if(flag_read)//访问结构体成功，结构体有内容
	    {
		flag_scan_update_user++;
		new_point=malloc(sizeof(T_LINK));
		memset(new_point,0,sizeof(T_LINK));

		strcpy(new_point->pass_word,tmp_info.pass_word);
		new_point->age=tmp_info.age;
		new_point->class=tmp_info.class;
		new_point->ID=tmp_info.ID;
		strcpy(new_point->name,tmp_info.name);
		strcpy(new_point->duty,tmp_info.duty);
		strcpy(new_point->teaching,tmp_info.teaching);

		if(p==NULL)
		{
		    new_point->next=NULL;
		    new_point->pre=p;
		    p->next=new_point;
		}					
		else
		{
		    new_point->pre=p;
		    new_point->next=p->next;
		    p->next=new_point;
		}				
		p=p->next;					
	    }
	    else//结构体访问结束，即结构体已为空或访问到文件尾部
	    {
		fclose(read);
		break;
	    }
	}
    }
}



void read_student_info(S_LINK **head)//读取学生文件内容至链表
{
    S_INFO tmp_info;
    int flag_read;
    int flag_scan_update_user=0;

    FILE *read;

    S_LINK*p;
    S_LINK*new_point;

    *head=malloc(sizeof(S_LINK));
    memset(*head,0,sizeof(S_LINK));
    p=*head;

    read=fopen(SPATH,"rb");//读取已有帐号和密码保存的文件

    if(read==NULL)//文件打开失败，帐号和密码保存的那个文件不存在时触发
    {
	read=fopen(SPATH,"w");
	fclose(read);
	return;
    }
    else//文件打开成功，进入帐号和密码匹配
    {
	while(1)//循环读取结构体的帐号和密码，读完整个文件退出循环
	{
	    fseek(read,flag_scan_update_user*sizeof(S_INFO),SEEK_SET);
	    flag_read=fread(&tmp_info,sizeof(S_INFO),1,read);

	    if(flag_read)//访问结构体成功，结构体有内容
	    {
		flag_scan_update_user++;
		new_point=malloc(sizeof(S_LINK));
		memset(new_point,0,sizeof(S_LINK));

		strcpy(new_point->pass_word,tmp_info.pass_word);
		new_point->age=tmp_info.age;
		new_point->c_score=tmp_info.c_score;
		new_point->english_score=tmp_info.english_score;
		new_point->math_score=tmp_info.math_score;
		new_point->line_num=tmp_info.line_num;
		new_point->class=tmp_info.class;
		new_point->ID=tmp_info.ID;
		strcpy(new_point->name,tmp_info.name);

		if(p==NULL)
		{
		    new_point->next=NULL;
		    new_point->pre=p;
		    p->next=new_point;
		}					
		else
		{
		    new_point->pre=p;
		    new_point->next=p->next;
		    p->next=new_point;
		}				
		p=p->next;					
	    }
	    else//结构体访问结束，即结构体已为空或访问到文件尾部
	    {
		fclose(read);
		break;
	    }
	}
    }
    sore_byline_num(head);
}


//*************************保存教师信息至文件*******************************//
void save_teacher_info(T_LINK *head)//保存教师信息至文件
{
    T_INFO tmp_info;
    
    FILE *write;

    T_LINK*p;

    p=head;
    p=p->next;

    write=fopen(TPATH,"w");//读取已有帐号和密码保存的文件
    fclose(write);

    while(p)//循环读取结构体的帐号和密码，读完整个文件退出循环
    {

	write=fopen(TPATH,"a");

	strcpy(tmp_info.pass_word,p->pass_word);
	tmp_info.age=p->age;
	tmp_info.class=p->class;
	tmp_info.ID=p->ID;
	strcpy(tmp_info.name,p->name);
	strcpy(tmp_info.duty,p->duty);
	strcpy(tmp_info.teaching,p->teaching);

	fwrite(&tmp_info,sizeof(T_INFO),1,write);

	p=p->next;
	fclose(write);
    }
}


//*************************保存学生信息至文件*******************************//
void save_student_info(S_LINK *head)//保存学生信息至文件
{
    S_INFO tmp_info;
    
    FILE *write;

    S_LINK*p;

    p=head;
    p=p->next;

    write=fopen(SPATH,"w");//读取已有帐号和密码保存的文件
    fclose(write);

    while(p)//循环读取结构体的帐号和密码，读完整个文件退出循环
    {

	write=fopen(SPATH,"a");

	strcpy(tmp_info.pass_word,p->pass_word);
	tmp_info.age=p->age;
	tmp_info.c_score=p->c_score;
	tmp_info.english_score=p->english_score;
	tmp_info.math_score=p->math_score;
	tmp_info.line_num=p->line_num;
	tmp_info.class=p->class;
	tmp_info.ID=p->ID;
	strcpy(tmp_info.name,p->name);

	fwrite(&tmp_info,sizeof(S_INFO),1,write);

	p=p->next;
	fclose(write);
    }
}	


//******************复制head到head_new*********************************************//
void copy_teacher_link(T_LINK *head,T_LINK **head_new)
{

    T_LINK *p;
    T_LINK *p_head_new;
    T_LINK *p_new;
    *head_new=malloc(sizeof(T_LINK));
    memset(*head_new,0,sizeof(T_LINK));
    p=head;
    p=p->next;
    p_head_new=*head_new;
    while(p)
    {
	p_new=malloc(sizeof(T_LINK));
	memset(p_new,0,sizeof(T_LINK));
	p_new->ID=p->ID;
	strcpy( p_new->name,p->name);
	p_new->class=p->class;
	p_new->age=p->age;
	strcpy(p_new->pass_word,p->pass_word);
	strcpy(p_new->duty,p->duty);
	strcpy(p_new->teaching,p->teaching);

	if(p_head_new==NULL)
	{
	    p_new->next=NULL;
	    p_new->pre=NULL;
	    p_head_new->next=p_new;
	}
	else
	{
	    p_new->pre=p_head_new;
	    p_new->next=p_head_new->next;
	    p_head_new->next=p_new;
	}
	p_head_new=p_head_new->next;
	p=p->next;
    }
//********************复制结束*******************************//
}

//******************复制head到head_new*********************************************//
void copy_student_link(S_LINK *head,S_LINK **head_new)
{
    S_LINK *p;
    S_LINK *p_head_new;
    S_LINK *p_new;
    *head_new=malloc(sizeof(S_LINK));
    memset(*head_new,0,sizeof(S_LINK));
    p=head;
    p=p->next;
    p_head_new=*head_new;
    while(p)
    {
	p_new=malloc(sizeof(S_LINK));
	memset(p_new,0,sizeof(S_LINK));
	p_new->ID=p->ID;
	strcpy( p_new->name,p->name);
	p_new->math_score=p->math_score;
	p_new->english_score=p->english_score;
	p_new->line_num=p->line_num;
	p_new->c_score=p->c_score;
	p_new->class=p->class;
	p_new->age=p->age;
	strcpy(p_new->pass_word,p->pass_word);

	if(p_head_new==NULL)
	{
	    p_new->next=NULL;
	    p_new->pre=p_head_new;
	    p_head_new->next=p_new;
	}
	else
	{
	    p_new->pre=p_head_new;
	    p_new->next=p_head_new->next;
	    p_head_new->next=p_new;
	}
	p_head_new=p_head_new->next;
	p=p->next;
    }
//********************复制结束*******************************//
}

void free_teacher_link(T_LINK **head_teacher)//删除并释放教师链表
{
    T_LINK *p;
    T_LINK *p_free;
    p_free=*head_teacher;
    p=(*head_teacher)->next;

    while(p_free->next)
    {
	if(p->next==NULL)
	{
	    p_free->next=NULL;
	}
	else
	{
	    p_free->next=p->next;
	}
	free(p);
	p_free=*head_teacher;
	p=(*head_teacher)->next;
    }
}

void free_student_link(S_LINK **head_student)//删除并释放学生链表
{
    S_LINK *p;
    S_LINK *p_free;
    p_free=*head_student;
    p=(*head_student)->next;

    while(p_free->next)
    {
	if(p->next==NULL)
	{
	    p_free->next=NULL;
	}
	else
	{
	    p_free->next=p->next;
	}
	free(p);
	p_free=*head_student;
	p=(*head_student)->next;
    }
}

void delete_one_teacher_in_link(T_LINK **head_teacher,char deletename[16])
{
    T_LINK *p;
    T_LINK *p_free;
    p_free=*head_teacher;
    p=(*head_teacher)->next;
    while(p_free->next)
    {
	if(0==strcmp(p->name,deletename))
	{
	    if(p->next==NULL)
	    {
		p_free->next=NULL;

	    }
	    else
	    {
		p_free->next=p->next;
		p->next->pre=p_free;
	    }
	    free(p);
	    break;
	}
	p_free=p_free->next;
	p=p->next;
    }
}

void delete_one_student_in_link(S_LINK **head_student,char deletename[16])
{
    S_LINK *p;
    S_LINK *p_free;
    p_free=*head_student;
    p=(*head_student)->next;
    while(p_free->next)
    {
	if(0==strcmp(p->name,deletename))
	{
	    if(p->next==NULL)
	    {
		p_free->next=NULL;

	    }
	    else
	    {
		p_free->next=p->next;
		p->next->pre=p_free;
	    }
	    free(p);
	    break;
	}
	p_free=p_free->next;
	p=p->next;
    }
}

void sore_byline_num(S_LINK **head)//学生排名算法函数
{

//*****************计算排名开始**************************//
//步骤： 将head保存到head_p_line,取出最高分数保存到head_p_sore

    int max_score_all;
    S_LINK *max_p,*tmp_p,*free_p,*p_sore,*p;
    S_LINK *head_p_sore=NULL;
    head_p_sore=malloc(sizeof(S_LINK));
    memset(head_p_sore,0,sizeof(S_LINK));
    p=*head;
    p=p->next;
    p_sore=head_p_sore;
    int line_num=0;

    while((*head)->next)
    {
	max_p=malloc(sizeof(S_LINK));
	memset(max_p,0,sizeof(S_LINK));
	p=(*head)->next;

	line_num++;
	max_score_all=-1;
	while(p)
	{
	    if(max_score_all<(p->c_score+p->english_score+p->math_score))
	    {
		max_p->ID=p->ID;
		strcpy( max_p->name,p->name);
		max_p->math_score=p->math_score;
		max_p->english_score=p->english_score;
		max_p->line_num=p->line_num;
		max_p->c_score=p->c_score;
		max_p->class=p->class;
		max_p->age=p->age;
		strcpy(max_p->pass_word,p->pass_word);

		max_score_all=(p->c_score+p->english_score+p->math_score);
	    }

	    p=p->next;
	}

	free_p=*head;
	tmp_p=*head;

	while(free_p->next)
	{
	    if(max_p->line_num==free_p->line_num)
	    {
		break;
	    }
	    tmp_p=free_p;
	    free_p=free_p->next;
	}

	if(free_p==*head)
	{
	    if(free_p->next)
	    {
	    free_p->next->pre=NULL;
	    *head=free_p->next;
	    }
	    else
	    {
		*head=NULL;
	    }
	}
	else
	{
	    if(free_p->next)
	    {
	    tmp_p->next=free_p->next;
	    free_p->next->pre=tmp_p;
	    }
	    else
	    {
		tmp_p->next=NULL;
	    }
	}

	free(free_p);
	max_p->line_num=line_num;
	if(p_sore==NULL)
	{
	    max_p->next=NULL;
	    max_p->pre=NULL;
	    p_sore=max_p;
	}					
	else
	{
	    max_p->next=p_sore->next;
	    max_p->pre=p_sore;
	    p_sore->next=max_p;
	}				
	p_sore=p_sore->next;					
    }

    *head=head_p_sore;

//****************计算排名结束***************************//
}

//按班级查看学生
void search_student_byclass(T_LINK *head_teacher ,S_LINK  *head_student)
{

    system("clear");
    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t******          管理员－查看班级所有学生       *******\n");
    printf("\t\t\t******************************************************\n");
    printf("\t\t\t                     当前用户：%s                    \n",user_name);
    printf("\t\t\t                                                      \n");


    int searchclass;
    printf("\n\n\t\t\t\t请输入要查询的班级: ");
    scanf("%d",&searchclass);

    getchar();
    S_LINK  *tmp_info;//变量保存来自密码文件的结构体内容，用于匹配帐号和密码
    tmp_info=head_student->next;

    printf("\n\t\t\t\t\t%d班所有学生列表\n\n",searchclass);
    printf("\t\t\t姓名\t\t密码\t\t学号\t年龄\tC语言\t英语\t数学\t排名\n");

    while(tmp_info)//循环读取结构体的帐号和密码，读完整个文件退出循环
    {

	if(tmp_info->class==searchclass)
	{
	    printf("\t\t\t%-16s",tmp_info->name);
	    printf("%-16s",tmp_info->pass_word);
	    printf("%2d",tmp_info->ID);
	    printf("%8d",tmp_info->age);
	    printf("%8d",tmp_info->c_score);
	    printf("%8d",tmp_info->english_score);
	    printf("%8d",tmp_info->math_score);
	    printf("%8d\n",tmp_info->line_num);
	}
	tmp_info=tmp_info->next;
    }


    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t                按回车键返回上一级菜单                \n");
    printf("\t\t\t******************************************************\n");
    getchar();
    getchar();
    look_student_info(head_teacher,head_student);

}//end search_student_byclass

//按学号查看学生 
void search_student_byID(T_LINK *head_teacher, S_LINK  *head_student)
{

    S_LINK *tmp_info;//变量保存来自密码文件的结构体内容，用于匹配帐号和密码

    tmp_info=head_student->next;
    int search_studentID;
    printf("\t\t\t搜索学生学号:");
    scanf("%d",&search_studentID);

    getchar();
	while(tmp_info)//循环读取结构体的帐号和密码，读完整个文件退出循环
	{
		if(search_studentID==tmp_info->ID)//匹配成功进入
		{
		    printf("\n\t\t\t学号为%d 的学生信息如下:",search_studentID);
		    printf("\n\t\t\t姓  名: %s",tmp_info->name);
		    printf("\n\t\t\t密  码: %s",tmp_info->pass_word);
		    printf("\n\t\t\t年  龄: %d",tmp_info->age);
		    printf("\n\t\t\t班  级: %d",tmp_info->class);
		    printf("\n\t\t\t排  名: %d",tmp_info->line_num);
		    printf("\n\t\t\tC成 绩: %d",tmp_info->c_score);
		    printf("\n\t\t\t英语成绩: %d",tmp_info->english_score);
		    printf("\n\t\t\t数学成绩: %d",tmp_info->math_score);
		    break;
		}
		tmp_info=tmp_info->next;
	}	
	if(tmp_info==NULL)
	{
		printf("\n\t\t\t\t找不到该学号的学生 !\n\n");
	}

    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t                按回车键返回上一级菜单                \n");
    printf("\t\t\t******************************************************\n");
    getchar();
    getchar();
    look_student_info(head_teacher,head_student);
}


void search_student_byname(T_LINK *head_teacher, S_LINK  *head_student)
{


    S_LINK *tmp_info;


    tmp_info=head_student->next;
    char search_student_Name[16];
    printf("\t\t\t搜索学生姓名:");
    scanf("%s",search_student_Name);



	while(tmp_info)//
	{
		if(0==strcmp(search_student_Name,tmp_info->name))//匹配成功进入
		{
		    printf("\n\t\t\t姓名为%s 的学生信息如下:",search_student_Name);
		    printf("\n\t\t\t学  号: %d",tmp_info->ID);
		    printf("\n\t\t\t密  码: %s",tmp_info->pass_word);
		    printf("\n\t\t\t年  龄: %d",tmp_info->age);
		    printf("\n\t\t\t班  级: %d",tmp_info->class);
		    printf("\n\t\t\t排  名: %d",tmp_info->line_num);
		    printf("\n\t\t\tC成 绩: %d",tmp_info->c_score);
		    printf("\n\t\t\t英语成绩: %d",tmp_info->english_score);
		    printf("\n\t\t\t数学成绩: %d",tmp_info->math_score);
		    break;
		}

		tmp_info=tmp_info->next;
	}
	if(tmp_info==NULL)
	{
	    printf("\n\t\t\t\t找不到该姓名的学生 !\n\n");
	}

	printf("\n\t\t\t******************************************************\n");
	printf("\t\t\t                按回车键返回上一级菜单                \n");
	printf("\t\t\t******************************************************\n");
	getchar();
	getchar();
	look_student_info(head_teacher,head_student);
}

//查看教师帐户函数里的函数
void look_list_teacher(T_LINK *head_teacher , S_LINK  *head_student)
{
    system("clear");
    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t******          管理员－查看教师列表           *******\n");
    printf("\t\t\t******************************************************\n");
    printf("\t\t\t                     当前用户：%s                    \n",user_name);
    printf("\t\t\t                                                      \n");

    T_LINK *tmp_info;//

    tmp_info=head_teacher->next;

    int flag_scan_check_user=1;
	printf("\t\t\t\t\t所有教师列表\n\n");
	printf("\t\t\t姓名\t\t密码\t\t年龄\t序号\t班级\t职 称\t\t任 教\n");

	while(tmp_info)//
	{

		    printf("\t\t%d    %-16s",flag_scan_check_user++,tmp_info->name);
		    printf("%-16s",tmp_info->pass_word);
		    printf("%6d",tmp_info->age);
		    printf("%8d",tmp_info->ID);
		    printf("%8d",tmp_info->class);
		    printf("\t%-16s",tmp_info->duty);
		    printf("\t%s\n",tmp_info->teaching);
	
		    tmp_info=tmp_info->next;
	}
	
    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t                按回车键返回上一级菜单                \n");
    printf("\t\t\t******************************************************\n");
    getchar();
    getchar();
    look_teacher_info(head_teacher,head_student);

}

void search_teacher_byID(T_LINK *head_teacher, S_LINK *head_student)
{

    T_LINK  *tmp_info;//变量保存来自密码文件的结构体内容，用于匹配帐号和密码


    tmp_info=head_teacher->next;
    int search_teacherID;
    printf("\t\t\t搜索教师序号:");
    scanf("%d",&search_teacherID);

    getchar();
    while(tmp_info)//循环读取结构体的帐号和密码，读完整个文件退出循环
    {

	if(search_teacherID==tmp_info->ID)//匹配成功进入
	{
	    printf("\n\t\t\t序号为%d的教师信息如下:",search_teacherID);
	    printf("\n\t\t\t姓 名: %s",tmp_info->name);
	    printf("\n\t\t\t密 码: %s",tmp_info->pass_word);
	    printf("\n\t\t\t年 龄: %d",tmp_info->age);
	    printf("\n\t\t\t班 级: %d",tmp_info->class);
	    printf("\n\t\t\t职 称: %s",tmp_info->duty);
	    printf("\n\t\t\t任 教: %s",tmp_info->teaching);
	    break;
	}
	tmp_info=tmp_info->next;
    }
    if(tmp_info==NULL)
    {
	printf("\n\t\t\t\t找不到该序号的教师 !\n\n");
    }
    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t                按回车键返回上一级菜单                \n");
    printf("\t\t\t******************************************************\n");
    getchar();
    getchar();
    look_teacher_info(head_teacher,head_student);

}


void search_teacher_byname(T_LINK *head_teacher ,S_LINK *head_student)
{


    T_LINK *tmp_info;//变量保存来自密码文件的结构体内容，用于匹配帐号和密码

    tmp_info=head_teacher->next;
    char search_teacher_Name[16];
    printf("\t\t\t搜索教师姓名:");
    scanf("%s",search_teacher_Name);

    while(tmp_info)//循环读取结构体的帐号和密码，读完整个文件退出循环
    {

	if(0==strcmp(search_teacher_Name,tmp_info->name))//匹配成功进入
	{
	    printf("\n\t\t\t姓名为%s 的教师信息如下:",search_teacher_Name);
	    printf("\n\t\t\t序 号: %d",tmp_info->ID);
	    printf("\n\t\t\t密 码: %s",tmp_info->pass_word);
	    printf("\n\t\t\t年 龄: %d",tmp_info->age);
	    printf("\n\t\t\t班 级: %d",tmp_info->class);
	    printf("\n\t\t\t职 称: %s",tmp_info->duty);
	    printf("\n\t\t\t任 教: %s",tmp_info->teaching);
	    break;
	}
	tmp_info=tmp_info->next;
    }
    if(tmp_info==NULL)
    {
	printf("\n\t\t\t\t找不到该姓名的教师 !\n\n");
    }
    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t                按回车键返回上一级菜单                \n");
    printf("\t\t\t******************************************************\n");
    getchar();
    getchar();
    look_teacher_info(head_teacher,head_student);

}



/***查看帐户信息函数里的函数***/

void look_teacher_info(T_LINK *head_teacher,S_LINK *head_student)
{
    system("clear");
    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t*******             管理员－查看教师帐户       *******\n");
    printf("\t\t\t******************************************************\n");
    printf("\t\t\t              当前用户：%s                            \n",user_name);
    printf("\t\t\t              请选择：1.查看教师列表                  \n");
    printf("\t\t\t                      2.按工号搜索教师                \n");
    printf("\t\t\t                      3.按姓名搜索教师                \n");
    printf("\t\t\t                      4.返回上一级菜单                \n");

    int chose=1;
    while(chose)
    {
	printf("\t\t\t\n");
	printf("\t\t\t");

	int sys_admin_home_1_3_chose;
	scanf("%d",&sys_admin_home_1_3_chose);

	getchar();
	chose=0;
	switch (sys_admin_home_1_3_chose)
	{
	    case 1:look_list_teacher(head_teacher,head_student);break;
	    case 2:search_teacher_byID(head_teacher,head_student);break;
	    case 3:search_teacher_byname(head_teacher,head_student);break;
	    case 4:look_users_info(head_teacher,head_student);break;
	    default :chose=1;
		     printf("\t\t\t\t选择错误，请重新输入 !\n");
	}
    }

}


void look_student_info(T_LINK *head_teacher, S_LINK  *head_student)
{
    system("clear");
    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t*******             管理员－查看学生帐户       *******\n");
    printf("\t\t\t******************************************************\n");
    printf("\t\t\t              当前用户：%s                            \n",user_name);
    printf("\t\t\t              请选择：1.查看学生列表                  \n");
    printf("\t\t\t                      2.按学号搜索学生                \n");
    printf("\t\t\t                      3.按姓名搜索学生                \n");
    printf("\t\t\t                      4.按班级查看学生                \n");
    printf("\t\t\t                      5.返回上一级菜单                \n");


    int chose=1;
    while(chose)
    {
	printf("\t\t\t\n");
	printf("\t\t\t");

	int sys_admin_home_1_3_chose;
	scanf("%d",&sys_admin_home_1_3_chose);

	getchar();
	chose=0;
	switch (sys_admin_home_1_3_chose)
	{
	    case 1:look_list_student(head_teacher,head_student);break;
	    case 2:search_student_byID(head_teacher,head_student);break;
	    case 3:search_student_byname(head_teacher,head_student);break;
	    case 4:search_student_byclass(head_teacher,head_student);break;
	    case 5:look_users_info(head_teacher,head_student);break;
	    default :chose=1;
		     printf("\t\t\t\t选择错误，请重新输入 !\n");
	}
    }

}


void look_list_student(T_LINK *head_teacher, S_LINK  *head_student)
{
    system("clear");
    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t******          管理员－查看学生列表           *******\n");
    printf("\t\t\t******************************************************\n");
    printf("\t\t\t                     当前用户：%s                    \n",user_name);
    printf("\t\t\t                                                      \n");
    printf("\t\t\t              请选择 1.按学号顺序显示                 \n");
    printf("\t\t\t                     2.按名次顺序显示                 \n");
    printf("\t\t\t                     3.按学科成绩显示                 \n");
    printf("\t\t\t                     4.查看默认学生列表                 \n");
    printf("\t\t\t                     5.返回上一级菜单                  \n");
    printf("\t\t\t                                                      \n");
    printf("\t\t\t                                                      \n");
    printf("\n\t\t\t");

    int flag_look_student_by;

    scanf("%d",&flag_look_student_by);
    getchar();


    if(flag_look_student_by==1)
    {
	S_LINK *head=NULL;
	S_LINK *p;
	S_LINK *p_new;
	S_LINK *head_sore=NULL;
	S_LINK *tmp_p;
	S_LINK *max_p;
	S_LINK *p_sore;
	S_LINK *free_p;


	head_sore=malloc(sizeof(S_LINK));
	memset(head_sore,0,sizeof(S_LINK));

	copy_student_link(head_student,&head);
	p_sore=head_sore;

	p=head;

	//****************************以下程序将输出递减排序*******************************//

	while(head->next)
	{
	    p=head->next;

	    max_p=malloc(sizeof(S_LINK));
	    memset(max_p,0,sizeof(S_LINK));

	    max_p->ID=-1;

	    while(p)
	    {
		if(p->ID>max_p->ID)
		{
		    max_p->ID=p->ID;
		    strcpy( max_p->name,p->name);
		    max_p->math_score=p->math_score;
		    max_p->english_score=p->english_score;
		    max_p->line_num=p->line_num;
		    max_p->c_score=p->c_score;
		    max_p->class=p->class;
		    max_p->age=p->age;
		    strcpy(max_p->pass_word,p->pass_word);

		}

		p=p->next;
	    }

	    free_p=head;
	    tmp_p=head;

	    while(free_p->next)
	    {
		if(max_p->ID==free_p->ID)
		{
		    break;
		}
		tmp_p=free_p;
		free_p=free_p->next;

	    }


	    if(free_p==head)
	    {
		if(free_p->next)
		{
		head=free_p->next;
		free_p->next->pre=head;
		}
		else
		{
		    head=NULL;
		}
	    }
	    else
	    {
		if(free_p->next)
		{
		tmp_p->next=free_p->next;
		free_p->next->pre=tmp_p;
		}
		else
		{

		    tmp_p->next=NULL;
		}
	    }

	    free(free_p);

	    if(p_sore==NULL)
	    {
		max_p->next=NULL;
		max_p->pre=NULL;
		p_sore=max_p;
	    }					
	    else
	    {
		max_p->next=p_sore->next;
		max_p->pre=p_sore;
		p_sore->next=max_p;
	    }				
	    p_sore=p_sore->next;					
	}



	//**********************************递减结束***************************************//


	//******************以下程序将输出按递增排序****************************//

	p=head;
	while(head_sore->next)
	{
	    tmp_p=head_sore;
	    free_p=head_sore->next;

	    p_new=malloc(sizeof(S_LINK));
	    memset(p_new,0,sizeof(S_LINK));
	    while(1)
	    {
		if(free_p->next==NULL)
		{
		    p_new->ID=free_p->ID;
		    strcpy( p_new->name,free_p->name);
		    p_new->math_score=free_p->math_score;
		    p_new->english_score=free_p->english_score;
		    p_new->line_num=free_p->line_num;
		    p_new->c_score=free_p->c_score;
		    p_new->class=free_p->class;
		    p_new->age=free_p->age;
		    strcpy(p_new->pass_word,free_p->pass_word);

		    if(p==NULL)
		    {
			p_new->next=NULL;
			p_new->pre=NULL;
			p=p_new;
		    }					
		    else
		    {
			p_new->next=p->next;
			p_new->pre=p;
			p->next=p_new;
		    }

		    tmp_p->next=free_p->next;
		    free(free_p);
		    break;

		}
		tmp_p=tmp_p->next;
		free_p=free_p->next;

	    }
	    p=p->next;
	}

	//***********************************递增排序结束**********************************************//

	system("clear");
	printf("\n\n\t\t\t\t\t按学号显示学生列表\n\n");
	printf("\t\t\t学号\t姓名\t\t密码\t\t年龄\tC语言\t英语\t数学\t排名\n");

	p=head->next;
	while(p)//循环读取结构体的帐号和密码，读完整个文件退出循环
	{
	    printf("\t\t\t%2d",p->ID);
	    printf("\t%-16s",p->name);
	    printf("%-16s",p->pass_word);
	    printf("%2d",p->age);
	    printf("%8d",p->c_score);
	    printf("%8d",p->english_score);
	    printf("%8d",p->math_score);
	    printf("%8d\n",p->line_num);
	    p=p->next;
	}


	printf("\n\t\t\t******************************************************\n");
	printf("\t\t\t                按回车键返回上一级菜单                \n");
	printf("\t\t\t******************************************************\n");
	getchar();
	getchar();
	look_list_student(head_teacher,head_student);
    }//end flag_look_student_by==1

    if(flag_look_student_by==2)
    {
	S_LINK *head=NULL;
	S_LINK *p;
	S_LINK *p_new;
	S_LINK *head_sore=NULL;
	S_LINK *tmp_p;
	S_LINK *max_p;
	S_LINK *p_sore;
	S_LINK *free_p;


	head_sore=malloc(sizeof(S_LINK));
	memset(head_sore,0,sizeof(S_LINK));

	copy_student_link(head_student,&head);
	p_sore=head_sore;
	p=head;

	//****************************以下程序将输出递减排序*******************************//

	while(head->next)
	{
	    p=head->next;

	    max_p=malloc(sizeof(S_LINK));
	    memset(max_p,0,sizeof(S_LINK));

	    max_p->line_num=-1;

	    while(p)
	    {
		if(p->line_num>max_p->line_num)
		{
		    max_p->ID=p->ID;
		    strcpy( max_p->name,p->name);
		    max_p->math_score=p->math_score;
		    max_p->english_score=p->english_score;
		    max_p->line_num=p->line_num;
		    max_p->c_score=p->c_score;
		    max_p->class=p->class;
		    max_p->age=p->age;
		    strcpy(max_p->pass_word,p->pass_word);

		}

		p=p->next;
	    }

	    free_p=head;
	    tmp_p=head;

	    while(free_p->next)
	    {
		if(max_p->line_num==free_p->line_num)
		{
		    break;
		}
		tmp_p=free_p;
		free_p=free_p->next;

	    }


	    if(free_p==head)
	    {
		if(free_p->next)
		{
		head=free_p->next;
		free_p->next->pre=head;
		}
		else
		{
		    head=NULL;
		}
	    }
	    else
	    {
		if(free_p->next)
		{
		tmp_p->next=free_p->next;
		free_p->next->pre=tmp_p;
		}
		else
		{
		    tmp_p->next=NULL;
		}
	    }

	    free(free_p);

	    if(p_sore==NULL)
	    {
		max_p->next=NULL;
		max_p->pre=p;
		p_sore=max_p;
	    }					
	    else
	    {
		max_p->next=p_sore->next;
		max_p->pre=p_sore;
		p_sore->next=max_p;
	    }				
	    p_sore=p_sore->next;					
	}



	//**********************************递减结束***************************************//


	//******************以下程序将输出按递增排序****************************//

	p=head;
	while(head_sore->next)
	{
	    tmp_p=head_sore;
	    free_p=head_sore->next;

	    p_new=malloc(sizeof(S_LINK));
	    memset(p_new,0,sizeof(S_LINK));
	    while(1)
	    {
		if(free_p->next==NULL)
		{
		    p_new->ID=free_p->ID;
		    strcpy( p_new->name,free_p->name);
		    p_new->math_score=free_p->math_score;
		    p_new->english_score=free_p->english_score;
		    p_new->line_num=free_p->line_num;
		    p_new->c_score=free_p->c_score;
		    p_new->class=free_p->class;
		    p_new->age=free_p->age;
		    strcpy(p_new->pass_word,free_p->pass_word);

		    if(p==NULL)
		    {
			p_new->next=NULL;
			p_new->pre=NULL;
			p=p_new;
		    }					
		    else
		    {
			p_new->next=p->next;
			p_new->pre=p;
			p->next=p_new;
		    }

		    tmp_p->next=free_p->next;
		    free(free_p);
		    break;

		}
		tmp_p=tmp_p->next;
		free_p=free_p->next;

	    }
	    p=p->next;
	}

	//***********************************递增排序结束**********************************************//

	system("clear");
	printf("\n\n\t\t\t\t\t按名次显示学生列表\n\n");
	printf("\t\t\t排名\t姓名\t\t密码\t\t学号\t年龄\tC语言\t英语\t数学\n");

	p=head->next;
	while(p)//循环读取结构体的帐号和密码，读完整个文件退出循环
	{
	    printf("\t\t\t%2d",p->line_num);
	    printf("\t%-16s",p->name);
	    printf("%-16s",p->pass_word);
	    printf("%2d",p->ID);
	    printf("%8d",p->age);
	    printf("%8d",p->c_score);
	    printf("%8d",p->english_score);
	    printf("%8d\n",p->math_score);
	    p=p->next;
	}


	printf("\n\t\t\t******************************************************\n");
	printf("\t\t\t                按回车键返回上一级菜单                \n");
	printf("\t\t\t******************************************************\n");
	getchar();
	getchar();
	look_list_student(head_teacher,head_student);
    }//end flag_look_student_by==2

    if(flag_look_student_by==3)
    {
	system("clear");
	printf("\n\t\t\t******************************************************\n");
	printf("\t\t\t******        管理员－按学科成绩显示学生列表     *******\n");
	printf("\t\t\t******************************************************\n");
	printf("\t\t\t                     当前用户：%s                    \n",user_name);
	printf("\t\t\t                                                      \n");
	printf("\t\t\t              请选择 1.按C语言成绩顺序显示                 \n");
	printf("\t\t\t                     2.按英语成绩顺序显示                 \n");
	printf("\t\t\t                     3.按数学成绩顺序显示                 \n");
	printf("\t\t\t                     4.返回上一级菜单                  \n");
	printf("\t\t\t                                                      \n");
	printf("\t\t\t                                                      \n");
	printf("\n\t\t\t");

	int flag_look_student_by_subject_score;

	scanf("%d",&flag_look_student_by_subject_score);

	getchar();
	if(flag_look_student_by_subject_score==1)
	{
	    S_LINK *head=NULL;
	    S_LINK *p;
	    S_LINK *head_sore=NULL;
	    S_LINK *tmp_p;
	    S_LINK *max_p;
	    S_LINK *p_sore;
	    S_LINK *free_p;


	    head_sore=malloc(sizeof(S_LINK));
	    memset(head_sore,0,sizeof(S_LINK));

	    copy_student_link(head_student,&head);
	    p_sore=head_sore;
	    p=head;

	    //****************************以下程序将输出递减排序*******************************//

	    while(head->next)
	    {
		p=head->next;

		max_p=malloc(sizeof(S_LINK));
		memset(max_p,0,sizeof(S_LINK));

		max_p->c_score=-1;

		while(p)
		{
		    if(p->c_score>max_p->c_score)
		    {
			max_p->ID=p->ID;
			strcpy( max_p->name,p->name);
			max_p->math_score=p->math_score;
			max_p->english_score=p->english_score;
			max_p->line_num=p->line_num;
			max_p->c_score=p->c_score;
			max_p->class=p->class;
			max_p->age=p->age;
			strcpy(max_p->pass_word,p->pass_word);

		    }

		    p=p->next;
		}

		free_p=head;
		tmp_p=head;

		while(free_p->next)
		{
		    if(max_p->c_score==free_p->c_score)
		    {
			break;
		    }
		    tmp_p=free_p;
		    free_p=free_p->next;

		}


		if(free_p==head)
		{
		    if(free_p->next)
		    {
		    head=free_p->next;
		    free_p->next->pre=head;
		    }
		    else
		    {
			head=NULL;
		    }
		}
		else
		{
		    if(free_p->next)
		    {
		    tmp_p->next=free_p->next;
		    free_p->next->pre=tmp_p;
		    }
		    else
		    {
			tmp_p->next=NULL;
		    }
		}

		free(free_p);

		if(p_sore==NULL)
		{
		    max_p->next=NULL;
		    max_p->pre=NULL;
		    p_sore=max_p;
		}					
		else
		{
		    max_p->next=p_sore->next;
		    max_p->pre=p_sore;
		    p_sore->next=max_p;
		}				
		p_sore=p_sore->next;					
	    }



	    //**********************************递减结束***************************************//

	    system("clear");
	    printf("\n\n\t\t\t\t\t按C语言成绩显示学生列表 (由高到低)\n\n");
	    printf("\t\t\t学号\t姓名\t\t密码\t\t年龄\tC语言\t英语\t数学\t排名\n");

	    int averc_score=0;
	    int flag_count=0;
	    p=head_sore->next;
	    while(p)//循环读取结构体的帐号和密码，读完整个文件退出循环
	    {
		printf("\t\t\t%2d",p->ID);
		printf("\t%-16s",p->name);
		printf("%-16s",p->pass_word);
		printf("%2d",p->age);
		printf("%8d",p->c_score);
		printf("%8d",p->english_score);
		printf("%8d",p->math_score);
		printf("%8d\n",p->line_num);

		averc_score=averc_score+(p->c_score);
		flag_count++;

		p=p->next;
	    }

	    printf("\n\t\t\tC语言成绩平均分为：%.2f\n\n",(float)averc_score/flag_count);

	    printf("\n\t\t\t******************************************************\n");
	    printf("\t\t\t                按回车键返回上一级菜单                \n");
	    printf("\t\t\t******************************************************\n");
	    getchar();
	    getchar();
	    look_list_student(head_teacher,head_student);



	}//end c_score
	
	
	if(flag_look_student_by_subject_score==2)
	{
	    S_LINK *head=NULL;
	    S_LINK *p;
	    S_LINK *head_sore=NULL;
	    S_LINK *tmp_p;
	    S_LINK *max_p;
	    S_LINK *p_sore;
	    S_LINK *free_p;


	    head_sore=malloc(sizeof(S_LINK));
	    memset(head_sore,0,sizeof(S_LINK));

	    copy_student_link(head_student,&head);
	    p_sore=head_sore;
	    p=head;

		//****************************以下程序将输出递减排序*******************************//

		while(head->next)
		{
		    p=head->next;

		    max_p=malloc(sizeof(S_LINK));
		    memset(max_p,0,sizeof(S_LINK));

		    max_p->english_score=-1;

		    while(p)
		    {
			if(p->english_score>max_p->english_score)
			{
			    max_p->ID=p->ID;
			    strcpy( max_p->name,p->name);
			    max_p->math_score=p->math_score;
			    max_p->english_score=p->english_score;
			    max_p->line_num=p->line_num;
			    max_p->c_score=p->c_score;
			    max_p->class=p->class;
			    max_p->age=p->age;
			    strcpy(max_p->pass_word,p->pass_word);

			}

			p=p->next;
		    }

		    free_p=head;
		    tmp_p=head;

		    while(free_p->next)
		    {
			if(max_p->english_score==free_p->english_score)
			{
			    break;
			}
			tmp_p=free_p;
			free_p=free_p->next;

		    }


		    if(free_p==head)
		    {
			if(free_p->next)
			{
			head=free_p->next;
			free_p->next->pre=head;
			}
			else
			{
			    head=NULL;
			}
		    }
		    else
		    {
			if(free_p->next)
			{
			tmp_p->next=free_p->next;
			free_p->next->pre=tmp_p;
			}
			else
			{
			    tmp_p->next=NULL;
			}
		    }

		    free(free_p);

		    if(p_sore==NULL)
		    {
			max_p->next=NULL;
			max_p->pre=NULL;
			p_sore=max_p;
		    }					
		    else
		    {
			max_p->next=p_sore->next;
			max_p->pre=p_sore;
			p_sore->next=max_p;
		    }				
		    p_sore=p_sore->next;					
		}


	    //**********************************递减结束***************************************//



	    system("clear");
	    printf("\n\n\t\t\t\t\t按英语成绩显示学生列表 (由高到低)\n\n");
	    printf("\t\t\t学号\t姓名\t\t密码\t\t年龄\tC语言\t英语\t数学\t排名\n");

	    int averenglish_score=0;
	    int flag_count=0;
	    p=head_sore->next;
	    while(p)//循环读取结构体的帐号和密码，读完整个文件退出循环
	    {
		printf("\t\t\t%2d",p->ID);
		printf("\t%-16s",p->name);
		printf("%-16s",p->pass_word);
		printf("%2d",p->age);
		printf("%8d",p->c_score);
		printf("%8d",p->english_score);
		printf("%8d",p->math_score);
		printf("%8d\n",p->line_num);

		averenglish_score=averenglish_score+(p->english_score);
		flag_count++;
		p=p->next;
	    }

	    printf("\n\t\t\t英语成绩平均分为：%.2f\n\n",(float)averenglish_score/flag_count);

	    printf("\n\t\t\t******************************************************\n");
	    printf("\t\t\t                按回车键返回上一级菜单                \n");
	    printf("\t\t\t******************************************************\n");
	    getchar();
	    getchar();
	    look_list_student(head_teacher,head_student);


	}//end english_score

	if(flag_look_student_by_subject_score==3)
	{
	    S_LINK *head=NULL;
	    S_LINK *p;
	    S_LINK *head_sore=NULL;
	    S_LINK *tmp_p;
	    S_LINK *max_p;
	    S_LINK *p_sore;
	    S_LINK *free_p;


	    head_sore=malloc(sizeof(S_LINK));
	    memset(head_sore,0,sizeof(S_LINK));

	    copy_student_link(head_student,&head);
	    p_sore=head_sore;
	    p=head;

		//****************************以下程序将输出递减排序*******************************//

		while(head->next)
		{
		    p=head->next;

		    max_p=malloc(sizeof(S_LINK));
		    memset(max_p,0,sizeof(S_LINK));

		    max_p->math_score=-1;

		    while(p)
		    {
			if(p->math_score>max_p->math_score)
			{
			    max_p->ID=p->ID;
			    strcpy( max_p->name,p->name);
			    max_p->math_score=p->math_score;
			    max_p->english_score=p->english_score;
			    max_p->line_num=p->line_num;
			    max_p->c_score=p->c_score;
			    max_p->class=p->class;
			    max_p->age=p->age;
			    strcpy(max_p->pass_word,p->pass_word);

			}

			p=p->next;
		    }

		    free_p=head;
		    tmp_p=head;

		    while(free_p->next)
		    {
			if(max_p->math_score==free_p->math_score)
			{
			    break;
			}
			tmp_p=free_p;
			free_p=free_p->next;

		    }


		    if(free_p==head)
		    {
			if(free_p->next)
			{
			head=free_p->next;
			free_p->next->pre=head;
			}
			else
			{
			    head=NULL;
			}
		    }
		    else
		    {
			if(free_p->next)
			{
			tmp_p->next=free_p->next;
			free_p->next->pre=tmp_p;
			}
			else
			{
			    tmp_p->next=NULL;
			}
		    }

		    free(free_p);

		    if(p_sore==NULL)
		    {
			max_p->next=NULL;
			max_p->pre=NULL;
			p_sore=max_p;
		    }					
		    else
		    {
			max_p->next=p_sore->next;
			max_p->pre=p_sore;
			p_sore->next=max_p;
		    }				
		    p_sore=p_sore->next;					
		}


	    //**********************************递减结束***************************************//



	    system("clear");
	    printf("\n\n\t\t\t\t\t按数学成绩显示学生列表 (由高到低)\n\n");
	    printf("\t\t\t学号\t姓名\t\t密码\t\t年龄\tC语言\t英语\t数学\t排名\n");

	    int avermath_score=0;
	    int flag_count=0;
	    p=head_sore->next;
	    while(p)//循环读取结构体的帐号和密码，读完整个文件退出循环
	    {
		printf("\t\t\t%2d",p->ID);
		printf("\t%-16s",p->name);
		printf("%-16s",p->pass_word);
		printf("%2d",p->age);
		printf("%8d",p->c_score);
		printf("%8d",p->english_score);
		printf("%8d",p->math_score);
		printf("%8d\n",p->line_num);
		avermath_score=avermath_score+(p->math_score);
		flag_count++;
		p=p->next;
	    }
	    printf("\n\t\t\t数学成绩平均分为：%.2f\n\n",(float)avermath_score/flag_count);


	    printf("\n\t\t\t******************************************************\n");
	    printf("\t\t\t                按回车键返回上一级菜单                \n");
	    printf("\t\t\t******************************************************\n");
	    getchar();
	    getchar();
	    look_list_student(head_teacher,head_student);


	}//end math_socre


	if(flag_look_student_by_subject_score==4)
	{
	    look_list_student(head_teacher,head_student);

	}

	if(flag_look_student_by_subject_score>4||flag_look_student_by_subject_score<1)
	{
	    printf("\t\t\t\t输入错误！按回车键返回上一级菜单\n\t\t\t\t ");
	    getchar();
	    getchar();
	    system("clear");
	    look_list_student(head_teacher,head_student);
	}
    }//end flag_look_student_by==3

    if(flag_look_student_by==4)
    {

	S_LINK *tmp_info;//变量保存来自密码文件的结构体内容，用于匹配帐号和密码

	int flag_scan_check_user=1;
	tmp_info=head_student->next;
	system("clear");
	printf("\n\n\t\t\t\t\t所有学生列表\n");
	printf("\t\t\t姓名\t\t密码\t\t学号\t年龄\tC成绩\t英语\t数学\t排名\n");
	while(tmp_info)//循环读取结构体的帐号和密码，读完整个文件退出循环
	{

	    printf("\t\t%d       %-16s",flag_scan_check_user++,tmp_info->name);
	    printf("%-16s",tmp_info->pass_word);
	    printf("%2d",tmp_info->ID);
	    printf("%8d",tmp_info->age);
	    printf("%8d",tmp_info->c_score);
	    printf("%8d",tmp_info->english_score);
	    printf("%8d",tmp_info->math_score);
	    printf("%8d\n",tmp_info->line_num);

	    tmp_info=tmp_info->next;
	}

	printf("\n\t\t\t******************************************************\n");
	printf("\t\t\t                按回车键返回上一级菜单                \n");
	printf("\t\t\t******************************************************\n");
	getchar();
	getchar();
	look_list_student(head_teacher,head_student);

    }

    if(flag_look_student_by==5)
    {
	look_student_info(head_teacher,head_student);
    }

    if(flag_look_student_by>5||flag_look_student_by<1)
    {
	printf("\t\t\t\t输入错误！按回车键返回上一级菜单\n\t\t\t\t ");
	getchar();
	getchar();
	system("clear");
	look_student_info(head_teacher,head_student);
    }
}


int function_search_student_byname(S_LINK *head_student,char updatename[16])
{
    S_LINK *tmp_info;
    tmp_info=head_student->next;
    while(tmp_info)//循环读取结构体的帐号和密码，读完整个文件退出循环
    {
	if(0==strcmp(tmp_info->name,updatename))
	{
	    printf("\n\t\t\t%s的个人信息\t\t\t\n",updatename);
	    printf("\t\t\t名字\t\t学号\t密码\t\t年龄\t班级\tC成绩\t英语成绩\t数学成绩\t排名\n");
	    printf("\t\t\t%2s\t%d\t%2s\t%d\t%d\t%2d\t%2d\t\t%2d\t\t%d\n",tmp_info->name,tmp_info->ID,tmp_info->pass_word,tmp_info->age,tmp_info->class,tmp_info->c_score,tmp_info->english_score,tmp_info->math_score,tmp_info->line_num);

	    break;
	}
	tmp_info=tmp_info->next;
    }
    if(tmp_info==NULL)
    {
	printf("\n\t\t\t\t找不到该姓名的学生 !\n");
	return 0;
    }
    return 1;
}	

int function_search_teacher_byname(T_LINK *head_teacher,char updatename[16])
{
	T_LINK *tmp_info;
	tmp_info=head_teacher->next;



	while(tmp_info)//循环读取结构体的帐号和密码，读完整个文件退出循环
	{

	    if(0==strcmp(tmp_info->name,updatename))
	    {
		printf("\n\t\t\t%s的个人信息\t\t\t\n",updatename);
		printf("\t\t\t名字\t\t序号\t密码\t\t年龄\t班级\t职称\t\t任教\n");
		printf("\t\t\t%-16s%2d\t%-16s%2d%8d\t%-16s%16s\n",tmp_info->name,tmp_info->ID,tmp_info->pass_word,tmp_info->age,tmp_info->class,tmp_info->duty,tmp_info->teaching);

		break;
	    }
	    tmp_info=tmp_info->next;

	}
	if(tmp_info==NULL)
	{
	    printf("\n\t\t\t找不到该姓名的教师 !\n");
	    return 0;
	}
	return 1;
}

void manage_low_level_user(T_LINK **head_teacher,S_LINK **head_student)
{

    int flag_chose_update;
    char updatename[16];

    char keep_on;
    int are_link_change=0;

    system("clear");
    printf("\n\t\t\t\t\t请选择 1.修改教师账户信息\n");
    printf("\t\t\t                       2.修改学生账户信息\n");
    printf("\t\t\t                       3.删除教师账户信息\n");
    printf("\t\t\t                       4.删除学生账户信息\n");
    printf("\t\t\t                       5.新建教师账户信息\n");
    printf("\t\t\t                       6.新建学生账户信息\n");
    printf("\t\t\t                       7.返回上一级菜单\n\t\t\t");

    scanf("%d",&flag_chose_update);
    getchar();

    if(flag_chose_update==1)
    {
	printf("\n\t\t\t需要修改信息的教师的姓名 : ");
	scanf("%s",updatename);

	int found_user=0;
	found_user=function_search_teacher_byname(*head_teacher,updatename);
	if(found_user)
	{
		T_LINK *p_new=NULL;
		T_LINK *p;
		copy_teacher_link(*head_teacher,&p_new);

		
		p=p_new->next;
		
		while(p)
		{
		    if(0==strcmp(p->name,updatename))
		    {
			int oldID=p->ID;
			printf("\n\t\t\t修改%s的个人信息\t\t\t\n",updatename);
			printf("\t\t\t名字:");
			scanf("%s",p->name);
			printf("\t\t\t序号:");
			scanf("%d",&p->ID);
			printf("\t\t\t密码:");
			scanf("%s",p->pass_word);
			printf("\t\t\t年龄:");
			scanf("%d",&p->age);
			printf("\t\t\t班级:");
			scanf("%d",&p->class);
			printf("\t\t\t职称:");
			scanf("%s",p->duty);
			printf("\t\t\t任教:");
			scanf("%s",p->teaching);

			T_LINK *check_teacherID;
			check_teacherID=(*head_teacher)->next;
			while(check_teacherID)
			{
			    if(oldID!=p->ID)
			    {
				if(p->ID==check_teacherID->ID)
				{
				    printf("\t\t\t已存在的教师序号，不能重复！\n\t\t\t请重新输入序号：");
				    scanf("%d",&p->ID);
				    check_teacherID=(*head_teacher)->next;
				}
				else 
				{
				    check_teacherID=check_teacherID->next;
				}
			    }
			    else break;
			}
		    }
		    p=p->next;
		}
		free_teacher_link(head_teacher);
		*head_teacher=p_new;
		are_link_change=1;
	
	}
	printf("\n\t\t\t******************************************************\n");
	printf("\t\t\t                按回车键返回上一级菜单                \n");
	printf("\t\t\t******************************************************\n");
	getchar();
	getchar();
	manage_low_level_user(head_teacher,head_student);

    }


    if(flag_chose_update==2)
    {

	printf("\n\t\t\t需要修改信息的学生的姓名 : ");
	scanf("%s",updatename);

	int found_user=0;
	found_user=function_search_student_byname(*head_student,updatename);

	if(found_user)
	{

	    S_LINK*p_new=NULL;
	    S_LINK *p;

	    copy_student_link(*head_student,&p_new);

	    p=p_new->next;
	    while(p)
	    {
		if(0==strcmp(p->name,updatename))
		{
		    int oldID=p->ID;
		    printf("\n\t\t\t修改%s的个人信息:",updatename);
		    printf("名字、密码、学号、年龄、班级、C成绩、英语、数学\n");
		    printf("\t\t\t姓 名：");
		    scanf("%s",p->name);
		    printf("\t\t\t密 码：");
		    scanf("%s",p->pass_word);
		    printf("\t\t\t学 号：");
		    scanf("%d",&p->ID);
		    printf("\t\t\t年 龄：");
		    scanf("%d",&p->age);
		    printf("\t\t\t班 级：");
		    scanf("%d",&p->class);
		    printf("\t\t\tC成绩：");
		    scanf("%d",&p->c_score);
		    printf("\t\t\t英语成绩：");
		    scanf("%d",&p->english_score);
		    printf("\t\t\t数学成绩");
		    scanf("%d",&p->math_score);

		    S_LINK *check_studentID;
		    check_studentID=(*head_student)->next;
		    while(check_studentID)
		    {
			if(oldID!=p->ID)
			{
			    if(p->ID==check_studentID->ID)
			    {
				printf("\t\t\t已存在的学生学号，不能重复！\n\t\t\t请重新输入学号：");
				scanf("%d",&p->ID);
				check_studentID=(*head_student)->next;
			    }
			    else 
			    {
				check_studentID=check_studentID->next;
			    }
			}
			else break;
		    }
		}
		p=p->next;
	    }
	    free_student_link(head_student);
	    *head_student=p_new;
	    are_link_change=2;

	}	


	printf("\n\t\t\t******************************************************\n");
	printf("\t\t\t                按回车键返回上一级菜单                \n");
	printf("\t\t\t******************************************************\n");
	getchar();
	getchar();
	manage_low_level_user(head_teacher,head_student);

    }


    if(flag_chose_update==3)
    {

	printf("\n\t\t\t需要删除的教师的姓名 : ");
	scanf("%s",updatename);
	int found_user=0;
	found_user=function_search_teacher_byname(*head_teacher,updatename);//查找教师名字，有就返回1，没有为0
	if(found_user)
	{
	    delete_one_teacher_in_link(head_teacher,updatename);
	    are_link_change=1;
	}	

	printf("\n\t\t\t******************************************************\n");
	printf("\t\t\t                按回车键返回上一级菜单                \n");
	printf("\t\t\t******************************************************\n");
	getchar();
	getchar();
	manage_low_level_user(head_teacher,head_student);

    }

    if(flag_chose_update==4)
    {


	printf("\n\t\t\t需要删除的学生的姓名 : ");
	scanf("%s",updatename);
	int found_user=0;
	found_user=function_search_student_byname(*head_student,updatename);//查找学生名字，有就返回1，没有为0
	if(found_user)
	{
	    delete_one_student_in_link(head_student,updatename);
	    are_link_change=2;
	}	

	printf("\n\t\t\t******************************************************\n");
	printf("\t\t\t                按回车键返回上一级菜单                \n");
	printf("\t\t\t******************************************************\n");
	getchar();
	getchar();
	manage_low_level_user(head_teacher,head_student);

    }

    if(flag_chose_update==5)
    {
    
	T_LINK *p;
	T_LINK *p_new;
	p_new=malloc(sizeof(T_LINK));
	memset(p_new,0,sizeof(T_LINK));

	p=*head_teacher;

	while(p->next)
	{
	    p=p->next;
	}


	system("clear");
	printf("\n\n\t\t\t\t************添加 教师************\n\n");
	while(1)
	{
	    printf("\t\t\t********教师信息有:名字\t密码\t序号\t年龄\t班级\t职称\t任教********\n");
	    printf("\t\t\t名字:");
	    scanf("%s",p_new->name);
	    printf("\t\t\t密码:");
	    scanf("%s",p_new->pass_word);
	    printf("\t\t\t序号:");
	    scanf("%d",&p_new->ID);
	    printf("\t\t\t年龄:");
	    scanf("%d",&p_new->age);
	    printf("\t\t\t班级:");
	    scanf("%d",&p_new->class);
	    printf("\t\t\t职称:");
	    scanf("%s",p_new->duty);
	    printf("\t\t\t任教:");
	    scanf("%s",p_new->teaching);

	    T_LINK *check_teacherID;
	    check_teacherID=(*head_teacher)->next;
	    while(check_teacherID)
	    {
		if(p_new->ID==check_teacherID->ID)
		{
		    printf("\t\t\t已存在的教师序号，不能重复！\n\t\t\t请重新输入序号：");
		    scanf("%d",&p_new->ID);
		    check_teacherID=(*head_teacher)->next;
		}
		else 
		{
		    check_teacherID=check_teacherID->next;
		}
	    }

	    p_new->next=NULL;//添加新教师到链表
	    p->next=p_new;   //添加新教师到链表


	    printf("\t\t\t\t继续添加？(y/n) ");
	    getchar();
	    keep_on=getchar();
	    are_link_change=1;
	    if(keep_on!='y')break;

	}
	printf("\n\t\t\t\t添加教师成功\n\n");
	printf("\n\t\t\t******************************************************\n");
	printf("\t\t\t                按回车键返回上一级菜单                \n");
	printf("\t\t\t******************************************************\n");
	getchar();
	getchar();
	manage_low_level_user(head_teacher,head_student);

    }//end creat new teacher

    if(flag_chose_update==6)
    {

	S_LINK *p;
	S_LINK *p_new;
	p_new=malloc(sizeof(S_LINK));
	memset(p_new,0,sizeof(S_LINK));

	p=*head_student;

	while(p->next)
	{
	    p=p->next;
	}

	system("clear");
	printf("\n\n\t\t\t\t************添加 学生************\n\n");
	while(1)
	{
	    printf("\t\t\t******学生信息有：名字\t密码\t学号\t年龄\t班级\n\n");
	    printf("\t\t\t姓名：");
	    scanf("%s",p_new->name);
	    printf("\t\t\t密码：");
	    scanf("%s",p_new->pass_word);
	    printf("\t\t\t学号：");
	    scanf("%d",&p_new->ID);
	    printf("\t\t\t年龄：");
	    scanf("%d",&p_new->age);
	    printf("\t\t\t班级：");
	    scanf("%d",&p_new->class);

	    S_LINK *check_studentID;
	    check_studentID=(*head_student)->next;
	    while(check_studentID)
	    {
		if(p_new->ID==check_studentID->ID)
		{
		    printf("\n\t\t\t已存在的学生学号，不能重复！\n\t\t\t请重新输入学号：");
		    scanf("%d",&p_new->ID);
		    getchar();
		    check_studentID=(*head_student)->next;
		}
		else 
		{
		    check_studentID=check_studentID->next;
		}
	    }

	    p_new->next=NULL;//添加新学生到链表
	    p->next=p_new;   //添加新学生到链表


	    printf("\t\t\t\t继续添加？(y/n) ");
	    getchar();
	    keep_on=getchar();
	    are_link_change=2;
	    if(keep_on!='y')break;
	}
	printf("\n\n\t\t\t\t添加学生成功\n\n");
	printf("\n\t\t\t******************************************************\n");
	printf("\t\t\t                按回车键返回上一级菜单                \n");
	printf("\t\t\t******************************************************\n");
	getchar();
	getchar();
	manage_low_level_user(head_teacher,head_student);

    }//end creat new student

    if(flag_chose_update==7)
    {
	if(are_link_change)
	{
	    printf("\n\n\t\t\t\t您更改过帐户信息，是否保存？(y/n)");
	    keep_on=getchar();
	    if(keep_on=='y')
	    {
		printf("\n\t\t\t\t您的选择：保存");
		sore_byline_num(head_student);
		save_student_info(*head_student);
		save_teacher_info(*head_teacher);
		printf("\n\n\t\t\t\t保存成功！");

	    }
	    else
	    {
		printf("\n\t\t\t\t您的选择：不保存");
		free_student_link(head_student);
		free_teacher_link(head_teacher);
		read_student_info(head_student);
		read_teacher_info(head_teacher);
		printf("\n\n\t\t\t\t已取消更改操作！");
	    }
	}
	printf("\n");
	printf("\n");
	sleep(2);
	system("clear");
	sys_admin_home(head_teacher,head_student);
    }



	
}

void look_users_info(T_LINK *head_teacher,S_LINK *head_student)
{

    system("clear");
    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t*******             管理员－查看帐户信息       *******\n");
    printf("\t\t\t******************************************************\n");
    printf("\t\t\t              当前用户：%s                            \n",user_name);
    printf("\t\t\t              请选择：1.查看教师帐户                  \n");
    printf("\t\t\t                      2.查看学生帐户                  \n");
    printf("\t\t\t                      3.返回上一级菜单                \n");
    
    int chose=1;
    while(chose)
    {
	printf("\t\t\t\n");
	printf("\t\t\t");

	int sys_admin_home_1_3_chose;
	scanf("%d",&sys_admin_home_1_3_chose);

	getchar();
	chose=0;
	switch (sys_admin_home_1_3_chose)
	{
	    case 1:look_teacher_info(head_teacher,head_student);break;
	    case 2:look_student_info(head_teacher,head_student);break;
	    case 3:sys_admin_home(&head_teacher,&head_student);break;
	    default :chose=1;
		     printf("\t\t\t\t选择错误，请重新输入!\n");
	}
    }
}





void sys_admin_home(T_LINK **head_teacher,S_LINK **head_student)
{
    system("clear");
    printf("\n\t\t\t******************************************************\n");
    printf("\t\t\t*******             管理员主界面               *******\n");
    printf("\t\t\t******************************************************\n");
    printf("\t\t\t              当前用户：%s                            \n",user_name);
    printf("\t\t\t              请选择  1.修改帐户信息                  \n");
    printf("\t\t\t                      2.查看帐户信息                  \n");
    printf("\t\t\t                      3.退出登录                      \n");

    int chose=1;
    while(chose)
    {
	printf("\t\t\t\n");
	printf("\t\t\t");
	int sys_admin_home_1_chose;
	scanf("%d",&sys_admin_home_1_chose);

	getchar();
	chose=0;
	switch (sys_admin_home_1_chose)
	{
	    case 1:manage_low_level_user(head_teacher,head_student);break;
	    case 2:look_users_info(*head_teacher,*head_student);break;
	    case 3:sys_admin_logout();break;
	    default :chose=1;
		     printf("\t\t\t\t选择错误，请重新输入!\n");
	}
    }
}

//登录函数  
void sys_admin_login(T_LINK **head_teacher,S_LINK **head_student)
{
    printf("\n\n\t\t\t\t>>>>>>>管理员登录<<<<<<<\n");
    static int flag_enter_user_error_count=0;//输入错误次数统计，大于10次退出
    printf("\t\t\t用户名:");
    scanf("%s",user_name);
    printf("\t\t\t密  码:");
    scanf("%s",pass_word);

    if((0==strcmp(user_name,"admin"))&&(0==strcmp(pass_word,"admin")))
    {
	flag_enter_user_error_count=0;
	sys_admin_login_success();//显示登录成功界面
	sys_admin_home(head_teacher,head_student);//进入管理员功能
	return ;
    }
    else
    {
	flag_enter_user_error_count++;
	if(flag_enter_user_error_count>2)//输入错误大于3，退出程序
	{
	    flag_enter_user_error_count=0;
	    printf("\n\n\n\n\t\t\t>>>>>>>>>输入错误太多，不给机会你登录了<<<<<<<<<<\n\n\n");
	    sleep(2);
	    exit_system(head_teacher,head_student);
	}
	else	
	{
	    printf("\t\t\t\t验证失败！请重新输入!\n");
	    sys_admin_login(head_teacher,head_student);
	}
    }
}

void sys_admin_login_success()
{
    system("clear");
    printf("\n\t\t\t******************************************************\t\t\t\n");
    printf("\t\t\t***************  TT TT           TT TT     ***********\t\t\t\n");
    printf("\t\t\t**************   IIXII           IIXII      **********\t\t\t\n");
    printf("\t\t\t************     II II           II II       *********\t\t\t\n");
    printf("\t\t\t************                                 *********\t\t\t\n");
    printf("\t\t\t************           用户登录成功          *********\t\t\t\n");
    printf("\t\t\t************                                 *********\t\t\t\n");
    printf("\t\t\t*************            欢迎使用           **********\t\t\t\n");
    printf("\t\t\t**************                             ***********\t\t\t\n");
    printf("\t\t\t*****************                        *************\t\t\t\n");
    printf("\t\t\t******************************************************\n\t\t\t");
    getchar();
    getchar();
}
void sys_admin_logout()
{
    system("clear");
    printf("\n\t\t\t*****************************************************\t\t\t\n");
    printf("\t\t\t***************  x x            x x       ***********\t\t\t\n");
    printf("\t\t\t**************    x              x         **********\t\t\t\n");
    printf("\t\t\t************     x x            x x         *********\t\t\t\n");
    printf("\t\t\t************                                *********\t\t\t\n");
    printf("\t\t\t************          退出登录成功          *********\t\t\t\n");
    printf("\t\t\t************                                *********\t\t\t\n");
    printf("\t\t\t*************           再    见           **********\t\t\t\n");
    printf("\t\t\t**************                            ***********\t\t\t\n");
    printf("\t\t\t*****************                       *************\t\t\t\n");
    printf("\t\t\t*****************************************************\n\t\t\t");
    getchar();
    system("clear");
    welcome();
    welcome_chose_enter_login();
}
